Imports OMANE.Common.UI
Imports System.Collections.ObjectModel
Imports System.Windows
Imports Infragistics.Windows.Chart
Imports System.Windows.Controls
Imports System.ComponentModel
Imports PTIC_GestionBDD
Imports Microsoft.Practices.Prism.Commands


''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Public Class VMDataImport
    Inherits VMSectionBase

    Private manager As BddManager
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Sub New(ByVal manager As BddManager)
        Title = "IMPORT"
        Me.manager = manager
    End Sub
    '#Region "Variables privées"

    Sub New(ByVal editmode As Boolean)
        Title = "IMPORT"
    End Sub

    Private _cmdParcourir As DelegateCommand
    Private _cmdVisualiser As DelegateCommand
    '#End Region



    '#Region "Propriétés"


    '        ''' <summary>
    '        ''' Traitement d'import de la table d'encours
    '        ''' </summary>
    '        ''' <value></value>
    '        ''' <returns></returns>
    '        ''' <remarks></remarks>
    '        Public ReadOnly Property TraitementImportEncours As tableBDD
    '            Get
    '                Return Model.Univers.listeTraitements.TraitTbleEncours
    '            End Get
    '        End Property
    '#End Region

    '#Region "Commandes"

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Property cmdParcourir() As DelegateCommand
        Get
            If _cmdParcourir Is Nothing Then
                createCmd()
            End If
            Return _cmdParcourir
        End Get
        Private Set(ByVal value As DelegateCommand)
            _cmdParcourir = value
        End Set
    End Property
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Property cmdVisualiser() As DelegateCommand
        Get
            If _cmdVisualiser Is Nothing Then
                createCmd()
            End If
            Return _cmdVisualiser
        End Get
        Private Set(ByVal value As DelegateCommand)
            _cmdVisualiser = value
        End Set
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub cmdParcourirExecute()
        Dim openFileDialog1 As New Microsoft.Win32.OpenFileDialog
        openFileDialog1.InitialDirectory = PTIC_Util.ConstantesOMANE.csteEmplacementDefautTbleEncours
        openFileDialog1.DefaultExt = ".sas7bdat"
        openFileDialog1.Filter = "Table SAS (*.sas7bdat)|*.sas7bdat|Fichiers access (*.mdb)|*.mdb"
        If openFileDialog1.ShowDialog() Then
            'Initilisation du traitement de la table d'encours et de la librairie d'encours SAS
            Dim nomBDDEncours As New Cla_NomFichier(openFileDialog1.FileName)

            Dim mdlomane = ModuleIndicateurs.AppInstance.GetService(Of OMANE.Common.Model.Interfaces.IModelOMANE)()



            mdlomane.Connection.AssignLibName(nomBDDEncours.NomRepertoire, PTIC_Util.csteLibSASEncours)

            If Not mdlomane.ListeTraitements.ContainsKey(PTIC_Util.nomTraitTbleEncours) Then
                Dim initialiseurTableBDD As New initialiseurTableBDDEncours(PTIC_Util.csteEmplacementParametrage & "lstMappingEncours.xml")
                mdlomane.ListeTraitements.Add(PTIC_Util.nomTraitTbleEncours, New TableBDD_SAS(PTIC_Util.nomTraitTbleEncours, _
                   PTIC_Util.csteLibSASEncours, initialiseurTableBDD, ))
            End If
            'Dim result As tableBDD = Item(nomTraitTbleEncours)
            'Dim e As New PropertyGetEventArgs(Of tableBDD)(result, result)
            'RaiseEvent TraitTbleEncoursGet(Me, e)
            'Return e.returnValue

            mdlomane.ListeTraitements(PTIC_Util.nomTraitTbleEncours).FichierBDD.NomComplet = nomBDDEncours.NomComplet

            MyBase.OnPropertyChanged("TraitementImportEncours")
        End If

    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Function cmdParcourirCanExecute() As Boolean
        Return True
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub cmdVisualiserExecute()
        '            Dim ui = ModuleTauxGaranti._app.GetService(Of IUIService)()
        '            Model.Univers.listeTraitements.TraitTbleEncours.Calculer_DataTable()
        '            Dim tbe As DataTable = Model.Univers.listeTraitements.TraitTbleEncours.DataTableResultat
        '            ui.ShowMessage(New ViewModelPreviewBase(tbe), _
        '                           Width:=800, _
        '                           Height:=600)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Function cmdVisualiserCanExecute() As Boolean
        Return True
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub createCmd()
        cmdParcourir = New DelegateCommand(AddressOf cmdParcourirExecute, AddressOf cmdParcourirCanExecute)
        cmdVisualiser = New DelegateCommand(AddressOf cmdVisualiserExecute, AddressOf cmdVisualiserCanExecute)
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property TraitementImportEncours As tableBDD
        Get
            Dim mdlomane = ModuleIndicateurs.AppInstance.GetService(Of OMANE.Common.Model.Interfaces.IModelOMANE)()

            If Not mdlomane.ListeTraitements.ContainsKey(PTIC_Util.nomTraitTbleEncours) Then Return Nothing

            Return mdlomane.ListeTraitements(PTIC_Util.nomTraitTbleEncours)

            Return Nothing
        End Get
    End Property


End Class
